/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * CDialogoLookup.java
 *
 * Created on 18/06/2010, 16:42:45
 */

package rpt.bd.cenario;

/**
 *
 * @author Roberto
*/

public class CDialogoLookup extends CPainelBdCenarioEdicao {

    CConectorBd fConectorBd = null;
    CEstruturaCampoRegistroBdLookup fEstruturaCampoRegistroBdLookup = null;
    String fNomeTabela = null;
    String fAliasTabela = null;
    Object fCondicao = null;

    /** Creates new form CDialogoLookup */
    public CDialogoLookup(
        CConectorBd aConectorBd,
        CEstruturaCampoRegistroBdLookup aEstruturaCampoRegistroBdLookup,
        String aNomeTabela,
        String aAliasTabela,
        String aNomeChavePrimaria,
        String aNomeCampoDescricao,
        Object aCondicao) {
        //
        initComponents();
        fConectorBd = aConectorBd;
        aEstruturaCampoRegistroBdLookup = fEstruturaCampoRegistroBdLookup;
        fNomeTabela = aNomeTabela;
        fNomeCampoChavePrimaria = aNomeChavePrimaria;
        fNomeCampoDescricao = aNomeCampoDescricao;
        fCondicao = aCondicao;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        swPnlIdentificacao = new javax.swing.JPanel();
        swLblId = new javax.swing.JLabel();
        swTxfId = new javax.swing.JTextField();
        swLblDescricao = new javax.swing.JLabel();
        swTxfDescricao = new javax.swing.JTextField();

        setPreferredSize(new java.awt.Dimension(200, 200));

        swPnlIdentificacao.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "LOOKUP", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(0, 0, 153))); // NOI18N

        swLblId.setText("ID:");

        swLblDescricao.setText("Descrição:");

        javax.swing.GroupLayout swPnlIdentificacaoLayout = new javax.swing.GroupLayout(swPnlIdentificacao);
        swPnlIdentificacao.setLayout(swPnlIdentificacaoLayout);
        swPnlIdentificacaoLayout.setHorizontalGroup(
            swPnlIdentificacaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(swPnlIdentificacaoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(swPnlIdentificacaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(swLblDescricao)
                    .addComponent(swLblId))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(swPnlIdentificacaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(swTxfId, javax.swing.GroupLayout.DEFAULT_SIZE, 88, Short.MAX_VALUE)
                    .addComponent(swTxfDescricao, javax.swing.GroupLayout.DEFAULT_SIZE, 88, Short.MAX_VALUE))
                .addContainerGap())
        );
        swPnlIdentificacaoLayout.setVerticalGroup(
            swPnlIdentificacaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(swPnlIdentificacaoLayout.createSequentialGroup()
                .addGroup(swPnlIdentificacaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(swTxfId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(swLblId))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(swPnlIdentificacaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(swTxfDescricao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(swLblDescricao))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(swPnlIdentificacao, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(swPnlIdentificacao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(105, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    @Override
    public void preparar() {
        super.preparar();
        if (fNomeTabela != null) {
            fPersistenciaBd.setNomeTabela(fNomeTabela,fAliasTabela);
            fPersistenciaBd.setNomeChavePrimaria(fNomeCampoChavePrimaria);
        }
    }

    @Override
    public CEstruturaRegistroBd getEstruturaRegistroBd(final CCenarioBd aCenarioBd) {
        fCenarioBd = aCenarioBd;
        if (fEstruturaRegistroBd == null) {
            fEstruturaRegistroBd = new CEstruturaRegistroBdCenarioEdicao((CCenarioBdEdicao)aCenarioBd,fNomeCampoChavePrimaria,fNomeCampoDescricao,fCondicao);
            adic (
                "ID",fNomeCampoChavePrimaria,swTxfId,
                null,ETipoCampoBd.inteiro,true,false,
                10,false,true,false,false,-1,-1);
            adic(
                "Descriçao",fNomeCampoDescricao,swTxfDescricao,
                null,ETipoCampoBd.texto,true,false,
                10,true,true,true,true,-1,-1);
        }
       return fEstruturaRegistroBd;
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel swLblDescricao;
    private javax.swing.JLabel swLblId;
    private javax.swing.JPanel swPnlIdentificacao;
    private javax.swing.JTextField swTxfDescricao;
    private javax.swing.JTextField swTxfId;
    // End of variables declaration//GEN-END:variables

}
